package com.neudu.yiyang.controller;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.neudu.yiyang.commons.JSONReturn;
import com.neudu.yiyang.pojo.Customer;
import com.neudu.yiyang.service.CustomerService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
public class bedChange {
    @Autowired
    private CustomerService customerService;
    @Autowired
    private JSONReturn jsonReturn;
    @RequestMapping("get_all_bedlist")
    public String getAll(@RequestBody PageInfo pageInfo) {
        try {
            PageHelper.startPage(pageInfo.getPageNum(), pageInfo.getPageSize());
            List<Customer> list = customerService.list();
            PageInfo<Customer> pageInfoReturn = new PageInfo<>(list);
            return jsonReturn.returnSuccess(pageInfoReturn);
        } catch (Exception e) {
            e.printStackTrace();
            return jsonReturn.returnError(e.getMessage());
        }
    }
    @RequestMapping("getbedlistby_id")
    public String getById(@RequestParam("customerid") Integer customerid){
        try {
            Customer customer = customerService.getById(customerid);
            return jsonReturn.returnSuccess(customer);
        } catch (Exception e) {
            e.printStackTrace();
            return jsonReturn.returnError(e.getMessage());
        }
    }
    @RequestMapping("modifybedlistby_id")
    public String modifyById(@RequestBody Customer customer){
        try {
            customerService.updateById(customer);
            return jsonReturn.returnSuccess(customer);
        } catch (Exception e) {
            e.printStackTrace();
            return jsonReturn.returnError(e.getMessage());
        }
    }
}
